package org.mcf.DaoImpl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.commons.dbutils.handlers.MapListHandler;
import org.diyi.Tools.BaseDao;
import org.diyi.bean.Orderdetail;
import org.mcf.Dao.OrderdetailDao;

public class OdetailDaoImpl extends BaseDao implements OrderdetailDao{

	@Override
	public Integer insertDetails(Orderdetail info) {
String sql="insert into orderdetail(orderid,amount,money,productid,userid) values(0,?,?,?,?)";
		try {
			return query.update(sql,info.getAmount(),info.getMoney(),info.getProductid(),info.getUserid());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer deleteDetails(int proid,int userid) {
		String sql="delete from orderdetail where productid=? and userid=?";
		try {
			return query.update(sql,proid,userid);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public List<Map<String, Object>> selectDetails(int id) {
		String sql="select o.*,p.Presentprice,p.originalprice,p.content,i.imgid from orderdetail o,product p,image i where o.orderid=? and o.productid=p.productid and p.imgid=i.id";
		try {
			return query.query(sql, new MapListHandler(),id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
